package br.com.winesys.geta.base;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Lê o texto a partir de um determinado recurso
 * @author ederson
 *
 */
public final class ResourceReader {

	private ResourceReader() {

	}

	/**
	 * Lê o texto a partir de um determinado recurso
	 * 
	 * @param resource Recurso que contém o texto a ser lido
	 * @return texto do recurso
	 * @throws IOException 
	 */
	public static String loadStringFromResource(InputStream resource) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(resource));
		StringBuffer result = new StringBuffer();
		String aux = reader.readLine();
		boolean added = false;
		while (aux != null) {
			if (added){
				result.append(System.getProperty("line.separator"));
			}
			result.append(aux);
			aux = reader.readLine();
			added = true;
		}
		reader.close();
		return result.toString();
	}
}